<!--
 * @Description: 变更单
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-07-19 17:38:41
 * @FilePath: /yuxiuproweb/src/views/split/order/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="订单编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select
          v-model="queryParams.state"
          placeholder="请选择状态"
          clearable
        >
          <el-option label="未审核" value="0" />
          <el-option label="已审核" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pro:product:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="productList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="variationOrderId">
        <template slot-scope="{ row }">
          <el-link type="primary" @click="handleDetail(row)">{{
            row.variationOrderId
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="销售单号" align="center" prop="orderId" />
      <el-table-column label="客户" align="center" prop="clientName" />
      <el-table-column
        label="位置"
        align="center"
        prop="content"
        min-width="150"
      />
      <el-table-column
        label="加工单号"
        prop="customCurtainIds"
        min-width="150"
        align="center"
      >
        <template slot-scope="{ row }">
          {{
            row.customCurtainIds
              ? `窗帘编号：${row.customCurtainIds}`
              : row.customWindowCurtainIds
              ? `窗幔编号：${row.customWindowCurtainIds}`
              : row.customOtherIds
              ? `其他编号：${row.customOtherIds}`
              : row.rawIds
              ? `成品原料编号：${row.rawIds}`
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="{ row }">
          {{ row.state === "0" ? "未审核" : row.state === "1" ? "已审核" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditor" />
      <el-table-column
        label="审核时间"
        align="center"
        prop="auditTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="70"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            :disabled="scope.row.state === '1'"
            @click="handleExamine(scope.row)"
            >审核</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:order:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情 -->
    <detail-view
      v-if="detail.show"
      :show.sync="detail.show"
      v-bind="detail"
      @update="getList()"
    ></detail-view>
  </div>
</template>

<script>
import { listProOrder, delProOrder, updateProOrder,updatemoneyProOrder } from "@/api/asc/order";
import DetailView from "./mods/detail.vue";
// import PrintView from "./mods/print.vue";
import commonMix from "@/utils/mixins/common";

export default {
  name: "Product",
  dicts: [
    "md_complex_machining_model_part_1",
    "md_complex_machining_model_part_2",
  ],
  components: {
    DetailView,
    // PrintView,
  },
  mixins: [commonMix],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品列表表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderId: null,
        state: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      detail: {
        show: false,
        data: null,
      },
      print: {
        show: false,
        data: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询变更单列表 */
    getList() {
      this.loading = true;
      listProOrder(this.queryParams).then((response) => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.productId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    handleDetail(row) {
      this.detail = {
        show: true,
        data: {
          ...row,
        },
      };
    },
    handleExamine(row) {
			this.$confirm("是否确定审核？", "提示", {
			  confirmButtonText: "确定",
			  cancelButtonText: "取消",
			  type: "warning",
			})
			  .then(() => {
						
			    updateProOrder({
			      ...row,
			      state: "1",
			    }).then((res) => {
			      this.getList();
			    });
			  })
			  .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm(
          '是否确认删除变更单编号为"' + row.variationOrderId + '"的数据项？'
        )
        .then(function () {
          return delProOrder(row.variationOrderId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "pro/variationOrder/export",
        {
          ...this.queryParams,
        },
        `order_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
